package com.aquarius.chapter2;
/**
 * 考虑使用静态工厂方法代替构造函数
 * @author aquarius
 *
 */
public class Person {

	private int id;
	
	private String name;
	
	private String sex;
	
	private String address;
	
	private static Person person_a; 
	
	private static Object obj = new Object();
	
	public Person(){
		
	}
	
	private Person(int id, String name, String sex, String address){
		this.id = id;
		this.name = name;
		this.sex = sex;
		this.address = address;
	}
	
	public static Person getInstance(){
		if(person_a == null){
			synchronized (obj) {
				person_a = new Person(1, "夏娃", "nv", "伊甸园");
			}
		}
		return person_a;
	}

	public int getId() {
		return id;
	}

	public Person setId(int id) {
		this.id = id;
		return this;
	}

	public String getName() {
		return name;
	}

	public Person setName(String name) {
		this.name = name;
		return this;
	}

	public String getSex() {
		return sex;
	}

	public Person setSex(String sex) {
		this.sex = sex;
		return this;
	}

	public String getAddress() {
		return address;
	}

	public Person setAddress(String address) {
		this.address = address;
		return this;
	}

	@Override
	public String toString() {
		return "Person [id=" + id + ", name=" + name + ", sex=" + sex + ", address=" + address + "]";
	}
	
}
